package com.tyrone.gateway.handler;

import com.tyrone.gateway.route.RouterManager;
import com.tyrone.gateway.route.bean.RequestInfo;
import com.tyrone.gateway.route.bean.RouteInfo;
import com.tyrone.gateway.route.filter.RequestFilter;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Collection;
import java.util.List;

public class HandlerManager {

    RequestFilter requestFilter = new RequestFilter();
    RouterManager routerManager = new RouterManager();

    /**
     * 路由前置处理器
     *
     * @param requestInfo
     */
    public void preHandle(RouteInfo routeInfo) {

        List<Handler> handlers = routeInfo.getHandlers();
        if (ObjectUtils.isEmpty(handlers)) return;

        for (Handler handler : handlers) {
            handler.preHandle();
        }


    }

    /**
     * 路由后置处理器
     *
     * @param routeInfo
     */
    public void postHandler(RouteInfo routeInfo) {
        List<Handler> handlers = routeInfo.getHandlers();
        if (ObjectUtils.isEmpty(handlers)) return;
        //执行路由处理器
        for (Handler handler : handlers) {
            handler.postHandle();
        }
    }

    List<Handler> getHandler(Integer handleChainId) {
        return null;
    }

}
